package vn.aptech.leaveManagementSystem.business.parse;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import vn.aptech.leaveManagementSystem.business.dto.Application;
import vn.aptech.leaveManagementSystem.business.dto.Department;
import vn.aptech.leaveManagementSystem.business.dto.Employee;
import vn.aptech.leaveManagementSystem.business.dto.Holiday;
import vn.aptech.leaveManagementSystem.business.dto.Position;

public class MyParse {

	public static Department toDepartment(ResultSet rs) throws SQLException {
		Department tempDep = new vn.aptech.leaveManagementSystem.business.dto.Department();
		try {
			tempDep.setIDDepartment(rs.getInt("IDDepartment"));
		} catch (Exception e) {
			tempDep.setIDDepartment(rs.getInt("DepartmentID"));
		}
		tempDep.setDepartmentName(rs.getString("DepartmentName"));
		return tempDep;
	}

	public static Position toPosition(ResultSet rs) throws SQLException {
		Position tempPos = new Position();
		try {
			tempPos.setIDPosition(rs.getInt("IDPosition"));
		} catch (Exception e) {
			tempPos.setIDPosition(rs.getInt("PositionID"));
		}
		tempPos.setPositionName(rs.getString("PositionName"));
		return tempPos;
	}

	public static Employee toEmployee(ResultSet rs) throws SQLException {
		Employee tempEmp = new Employee();
		try {
			tempEmp.setIDEmp(rs.getInt("IDEmp"));
		} catch (Exception e) {
			tempEmp.setIDEmp(rs.getInt("EmpID"));
		}
		tempEmp.setAddress(rs.getString("Address"));
		tempEmp.setBirthday(rs.getDate("Birthday"));
		try {
			tempEmp.setDepartmentID(rs.getInt("DepartmentID"));
		} catch (Exception e) {
			tempEmp.setDepartmentID(rs.getInt("IDDepartment"));
		}
		tempEmp.setEmail(rs.getString("Email"));
		tempEmp.setFirstName(rs.getString("FirstName"));
		tempEmp.setGender(rs.getBoolean("Gender"));
		tempEmp.setJoinDate(rs.getDate("JoinDate"));
		tempEmp.setLastName(rs.getString("LastName"));
		tempEmp.setPassword(rs.getString("Password"));
		tempEmp.setPhone(rs.getString("Phone"));
		try {
			tempEmp.setPositionID(rs.getInt("PositionID"));
		} catch (Exception e) {
			tempEmp.setPositionID(rs.getInt("IDPostion"));
		}
		tempEmp.setStatusEmp(rs.getBoolean("StatusEmp"));
		tempEmp.setUserName(rs.getString("UserName"));
		return tempEmp;
	}

	public static Application toApplication(ResultSet rs) throws SQLException {
		Application tempApp = new Application();
		tempApp.setIDApplication(rs.getInt("IDApplication"));
		tempApp.setContact(rs.getString("Contact"));
		try {
			tempApp.setEmpID(rs.getInt("EmpID"));
		} catch (Exception e) {
			tempApp.setEmpID(rs.getInt("IDEmp"));
		}
		tempApp.setEndDate(rs.getDate("EndDate"));
		tempApp.setReason(rs.getString("Reason"));
		tempApp.setStartDate(rs.getDate("StartDate"));
		tempApp.setStatus(rs.getInt("Status"));
		return tempApp;
	}

	public static Holiday toHoliday(ResultSet rs) throws SQLException {
		Holiday tempHol = new Holiday();
		tempHol.setIDHoliday(rs.getInt("IDHoliday"));
		tempHol.setEndDate(rs.getDate("EndDate"));
		tempHol.setEvent(rs.getString("Event"));
		tempHol.setStartDate(rs.getDate("StartDate"));
		return tempHol;
	}

	public static vn.aptech.leaveManagementSystem.business.dto.Configuration toConfiguration(
			ResultSet rs) throws SQLException {
		vn.aptech.leaveManagementSystem.business.dto.Configuration tempConfig = new vn.aptech.leaveManagementSystem.business.dto.Configuration();
		tempConfig.setIDConfiguration(rs.getInt("IDConfiguration"));
		tempConfig.setDescription(rs.getString("Description"));
		tempConfig.setParameter(rs.getInt("Parameter"));
		return tempConfig;
	}

	public static java.sql.Date toSqlDate(java.util.Date utilDate)
	{
		java.sql.Date sqlDate=new Date(utilDate.getYear(),utilDate.getMonth(), utilDate.getDate());
		return sqlDate;
	}
	
	public static void main(String[] args) throws SQLException {
		/*
		 * MyModel myModel=new MyModel(); ResultSet
		 * rs=myModel.departments.getDepartmentList(); rs.next(); Department
		 * dep=MyParse.toDepartment(rs);
		 * System.out.println(dep.getDepartmentName());
		 */

		/*
		 * MyModel myModel=new MyModel(); ResultSet
		 * rs=myModel.employees.getEmployeesListForAdmin(); rs.next(); Employee
		 * emp=MyParse.toEmployee(rs);
		 * System.out.println(emp.getFirstName()+" "+emp.getLastName());
		 */

		/*
		 * MyModel myModel=new MyModel(); ResultSet
		 * rs=myModel.applications.getApplication(4); rs.next(); Application
		 * app=MyParse.toApplication(rs); System.out.println(app.getReason());
		 */

		/*
		 * MyModel myModel=new MyModel(); ResultSet
		 * rs=myModel.holidays.getHolidayList(); rs.next(); Holiday
		 * hol=MyParse.toHoliday(rs); System.out.println(hol.getEvent());
		 */

		/*
		 * MyModel myModel=new MyModel(); ResultSet
		 * rs=myModel.configurations.getConfigurationsList(); rs.next();
		 * vn.aptech.leaveManagementSystem.business.dto.Configuration
		 * config=MyParse.toConfiguration(rs);
		 * System.out.println(config.getDescription());
		 */
	}

}
